<template>
	<view>
		<view>{{message}}</view>
		<button type="default" @click="init">第一步-初始化蓝牙模块</button>

		<button style="margin-top: 160rpx;" type="default" @click="startBluetooth">开始搜寻附近的蓝牙外围设备</button>
		<button style="margin-top: 160rpx;" type="default" @click="offBluetooth">关闭蓝牙模块</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				message: ''
			}
		},
		methods: {
			init() {
				let _this = this;
				uni.openBluetoothAdapter({
					success(res) {
						console.log(res)
					},
					fail(err) {
						_this.message = err.errMsg
					}
				})
			},
			startBluetooth() {
				uni.startBluetoothDevicesDiscovery({
					// services: ['FEE7'],只搜索主服务 UUID 为 FEE7 的设备
					success(res) {
						console.log(res)
						uni.stopBluetoothDevicesDiscovery()
					}
				})
			},
			offBluetooth(){
				uni.closeBluetoothAdapter()
			}
		}
	}
</script>

<style scoped>

</style>
